﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PageLayoutManager.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the PageLayoutManager class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine.BusinessLogic
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;

    /// <summary>
    /// Defines the PageLayoutManager class.
    /// </summary>
    public static class PageLayoutManager
    {
        public static BusinessObjects.PageLayout New()
        {
            return new Data.LazyPageLayout();
        }

        /// <summary>
        /// Initializes a new instance of the PageLayout class.
        /// </summary>
        /// <param name="pageId">The identity of the database table's row referencing this page.</param>
        public static BusinessObjects.PageLayout GetPageLayout(int pageId)
        {
            return Data.PageLayout.Select(pageId);
        }
        
        /// <summary>
        /// Initializes a new instance of the PageLayout class.
        /// </summary>
        /// <param name="pagePath">The virtual path for this page.</param>
        public static BusinessObjects.PageLayout GetPageLayout(string pagePath)
        {
            return Data.PageLayout.Select(pagePath);
        }

        /// <summary>
        /// Loads all content versions.
        /// </summary>
        /// <returns>A read-only list of page content versions.</returns>
        public static List<BusinessObjects.Content> GetPageContentVersionsInfo(BusinessObjects.PageLayout pageLayout)
        {
            return Data.PageLayout.GetPageContentVersionsInfo(pageLayout);
        }

        public static void SaveAndPublishContent(BusinessObjects.PageLayout page, string content, BusinessObjects.UserProfile profile)
        {
            Data.PageLayout.SaveAndPublishContent(page, content, profile);
        }

        public static List<BusinessObjects.Permission> GetPermissionsWithRoleInfo(string path)
        {
            return Data.PageLayout.GetPermissionsWithRoleInfo(path);
        }

        /// <summary>
        /// Saves a new PageLayout to the database.
        /// </summary>
        /// <returns>The inserted PageLayout with a newly populated Id field.</returns>
        public static BusinessObjects.PageLayout SaveAs(BusinessObjects.PageLayout pageLayout)
        {
            return Data.PageLayout.Insert(pageLayout);
        }

        /// <summary>
        /// Saves page updates to database.
        /// </summary>
        public static void Save(BusinessObjects.PageLayout pageLayout)
        {
            Data.PageLayout.Update(pageLayout);
        }

        /// <summary>
        /// Deletes this PageLayout from the database.
        /// </summary>
        public static void Delete(BusinessObjects.PageLayout pageLayout)
        {
            Data.PageLayout.Delete(pageLayout);
        }
    }
}